package com.netmera.mobile;

import java.util.ArrayList;
import java.util.List;

import v2.simpleUi.M_Caption;
import v2.simpleUi.M_Container;
import v2.simpleUi.M_InfoText;
import v2.simpleUi.M_ListWrapper;
import v2.simpleUi.ModifierInterface;
import v3.M_TextModifier;
import android.R;
import android.content.Context;

public class M_ChannelManager extends M_Container {

	public M_ChannelManager(final ArrayList<String> channels) {
		add(new M_Caption("Channel List"));
		add(new M_InfoText(R.drawable.ic_dialog_info,
				"Setup your Channels here"));
		add(new M_ListWrapper<String>(channels, "Add channel") {

			@Override
			public boolean addNewObjectToList(Context context, List<String> list) {
				list.add(new String(""));
				return true;
			}

			@Override
			public ModifierInterface getModifierFor(final String item) {
				return new M_TextModifier() {

					@Override
					public boolean save(String newValue) {
						channels.set(channels.indexOf(item), newValue);
						return true;
					}

					@Override
					public String load() {
						return item;
					}

					@Override
					public String getVarName() {
						return null;
					}
				};
			}

			@Override
			public boolean onDelete(String item) {
				return channels.remove(item);
			}

		});
	}
}
